//扩展
const md5=require('md5');
const svgCaptcha=require('svg-captcha');
const jwt=require('jsonwebtoken');//token
const {
    TOKEN_KEY
}=require('../config');

module.exports={
    createCode(){//验证码
        return svgCaptcha.create({
            size:4,
            ignoreChars:'0o1i',
            noise:2,
            color:true,
            background:'#cc9966'
        });
    },
    createToken(id){//token
        let data=JSON.stringify({
            id,
            iss:'1911B',
            tim:+new Date(),
            exp:+new Date()+2*3600*1000,
        });
        return jwt.sign(data,TOKEN_KEY).toString()
    },
    createId(username){//id
        return md5(JSON.stringify({
            username,
            tim:+new Date()
        }))
    }
}